package cs2340.todolist.JUnit;



import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

import org.junit.Test;

import cs2340.todolist.model.ToDoItem;
import cs2340.todolist.model.utility.SearchEngine;
import cs2340.todolist.model.utility.SearchEngine.FilterType;




	public class FilterByTypeTest {
		private long count = 0;
        private ToDoItem school1 = createToDoItem("Homework", "School");
        private ToDoItem school2 = createToDoItem("Project", "School");
        private ToDoItem school3 = createToDoItem("Test", "School");
        private ToDoItem work1 = createToDoItem("Promote Synergy", "Work");
        private ToDoItem work2 = createToDoItem("Micro-manage", "Work");
        private ToDoItem work3 = createToDoItem("Send Some Faxes", "Work");
        private ToDoItem personal1 = createToDoItem("Birthday Party", "Personal");
        private ToDoItem personal2 = createToDoItem("Wedding", "Personal");
        private ToDoItem personal3 = createToDoItem("Spa Day", "Personal");


	    @Test
	    public void testFilterByTypePersonal() {
	        ArrayList<ToDoItem> items = new ArrayList();
	        
	        items.add(school1);
	        items.add(work1);
	        items.add(personal1);
	        items.add(school2);
	        items.add(work2);
	        items.add(personal2);
	        items.add(school3);
	        items.add(work3);
	        items.add(personal3);
	       
	        
	        
	       // Checks to make sure that it has filters out all none-Personal items 
	        new FilterType(0).filter(items);
	        for (ToDoItem item : items) {
	            assertNotSame(school1, item);
	            assertNotSame(work1, item);    
	            assertNotSame(school2, item);
	            assertNotSame(work2, item);
	            assertNotSame(school3, item);
	            assertNotSame(work3, item);
	        }
	            
	        	//Makes sure the Personal Items are in the list
	        	assertTrue("personal1 is not in the list",items.contains(personal1));
	        	assertTrue("personal2 is not in the list",items.contains(personal2));
	        	assertTrue("personal3 is not in the list",items.contains(personal3));
	  
	    }
	    
	    
	    
	    @Test
	    public void testFilterBySchool() {
	        ArrayList<ToDoItem> items = new ArrayList();
	        
	        items.add(school1);
	        items.add(work1);
	        items.add(personal1);
	        items.add(school2);
	        items.add(work2);
	        items.add(personal2);
	        items.add(school3);
	        items.add(work3);
	        items.add(personal3);
	       
	        
	        
	       // Checks to make sure that it has filters out all none-School items 
	        new FilterType(1).filter(items);
	        for (ToDoItem item : items) {
	            assertNotSame(work1, item);
	            assertNotSame(personal1, item);    
	            assertNotSame(work2, item);
	            assertNotSame(personal2, item);
	            assertNotSame(work3, item);
	            assertNotSame(personal3, item);
	        }
	            
	        	//Makes sure the School Items are in the list
	        	assertTrue("Failed name case 1",items.contains(school1));
	        	assertTrue("Failed name case 1",items.contains(school2));
	        	assertTrue("Failed name case 1",items.contains(school3));  
	    }
	    
	    
	    @Test
	    public void testFilterByWork() {
	        ArrayList<ToDoItem> items = new ArrayList();
	        
	        items.add(school1);
	        items.add(work1);
	        items.add(personal1);
	        items.add(school2);
	        items.add(work2);
	        items.add(personal2);
	        items.add(school3);
	        items.add(work3);
	        items.add(personal3);
	       
	        
	        
	       // Checks to make sure that it has filters out all none-Work items 
	        new FilterType(2).filter(items);
	        for (ToDoItem item : items) {
	            assertNotSame(school1, item);
	            assertNotSame(personal1, item);    
	            assertNotSame(school2, item);
	            assertNotSame(personal2, item);
	            assertNotSame(school3, item);
	            assertNotSame(personal3, item);
	        }
	            
	        	//Makes sure the Work Items are in the list
	        	assertTrue("Failed name case 1",items.contains(work1));
	        	assertTrue("Failed name case 1",items.contains(work2));
	        	assertTrue("Failed name case 1",items.contains(work3));
	    	    
	    }
	    
	    
	    
	    //Method for making a quick ToDoItem
	    public ToDoItem createToDoItem(String title, String type) {
	        ToDoItem item = new ToDoItem(count, title, null , type, null, null, null);
	        return item;
	    }

	}


